<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>transition实现导航置顶效果</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body{
      height: 200vh;
    }
    .nav{
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      padding: 25px 100px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      transition:  0.5s;
    }

    .nav-list{
      position: relative;
      display: flex;
      justify-content: center;
      align-content: center;
      list-style: none;
    }
    a{
      position: relative;
      margin: 0 10px;
      font-size: 18px;
      font-family: 'fangsong';
      font-weight: bold;
      color: rgb(28, 36, 148);
      text-decoration: none;
    }

    .nav-change-to-top{
      padding: 15px 100px;
      background-color: rgb(71, 105, 219);
    }
    .nav-change-to-top a{
      color: rgb(252, 247, 247);
    }
  </style>
</head>
<body>
<!--  导航栏 -->
<div class="nav">
  <div class="logo"><a href="#">logo</a></div>
  <ul class="nav-list">
    <li><a href="#">主页</a></li>
    <li><a href="#">个人简介</a></li>
    <li><a href="#">文章</a></li>
    <li><a href="#">留言版</a></li>
    <li><a href="#">友链</a></li>
  </ul>
</div>
<script>
  window.addEventListener('scroll',function(){
    let navDom = document.querySelector('.nav');
    navDom.classList.toggle("nav-change-to-top", window.scrollY>0);
  })
  alert('进行滚动查看效果')
</script>
</body>
</html>
